package com.cskaoyan.controller.vx;

import com.cskaoyan.bean.MarketCoupon;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.CouponService;
import com.cskaoyan.service.VxCouponService;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/***
 * title VxCouponController
 * @description <TODO description class purpose>
 * @author ZCZ
 * @version 1.0.0
 * @create 2022/9/11 20:04
 **/
@RestController
@RequestMapping("wx/coupon")
public class VxCouponController {
    @Autowired
    VxCouponService vxCouponService;

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info) {
        CommonData<MarketCoupon> data = vxCouponService.list(info);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("mylist")
    public BaseRespVo myList(BasePageInfo info, Short status) {
        CommonData<MarketCoupon> data = vxCouponService.myList(info, status);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("receive")
    public BaseRespVo receive(@RequestBody Map<String,Integer> map) {
        int code = vxCouponService.receive(map);
        if (code==602) {return BaseRespVo.couponExchange2();}
        if (code==801) {return BaseRespVo.couponRecive1();}
        if (code==802) {return BaseRespVo.couponRecive2();}
        if (code==803) {return BaseRespVo.couponRecive3();}
        if (code==804) {return BaseRespVo.couponRecive4();}

        return BaseRespVo.ok3();
    }

    @RequestMapping("exchange")
    public BaseRespVo exchange(@RequestBody Map<String, String> map) {
        int code1 = vxCouponService.exchange(map);
        if (code1 == 601) { return BaseRespVo.couponExchange();}
        if (code1 == 602) { return BaseRespVo.couponExchange2(); }
        return BaseRespVo.ok3();
    }

    @RequestMapping("selectlist")
    public BaseRespVo selectList(int cartId) {
        CommonData<MarketCoupon> data = vxCouponService.selectList(cartId);
        return BaseRespVo.ok(data);
    }
}
